package com.joe.bibackend.config;

import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolExecutorConfig {

    public ThreadPoolExecutor threadPoolExecutorConfig(){
        ThreadFactory factory = new ThreadFactory() {

            private int count = 1;
            @Override
            public Thread newThread(@NotNull Runnable r) {
                Thread thread = new Thread(r);
                thread.setName("JoeThread: "+count);
                count++;
                return thread;
            }
        };

        return new ThreadPoolExecutor(2,4,100, TimeUnit.SECONDS,new ArrayBlockingQueue<>(4),factory);
    }
}
